<template>
  <el-form-item
    :label="label"
    :label-width="labelWidth"
    :prop="props.data.field"
    :required="props.data.required"
    :rules="props.data.rules"
  >
    <el-select
      v-model="val"
      :style="{ width: `${props.data.compWidth || 100}%` }"
      clearable
      :multiple="props.data.multiple"
      :placeholder="props.data.placeholder"
      :readonly="props.data.readonly"
      :disabled="props.data.disabled || props.data.readonly"
    >
      <el-option v-for="item in options" :key="item" :label="item" :value="item" />
    </el-select>
  </el-form-item>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { ElFormItem, ElSelect, ElOption } from 'element-plus'
import { useProps, useValue } from '../../common-props/hooks'

const props = defineProps<{ data: Record<string, any>; form: Record<string, any> }>()
const emits = defineEmits(['valueChange'])

const { label, labelWidth } = useProps(props)
const { val } = useValue(props, emits)

const options = computed(() => {
  const opts = props.data.options
  if (opts) {
    return opts.split('\n')
  } else {
    return []
  }
})
</script>

<style lang="scss" scoped></style>
